﻿#region Using directives
using System.Collections.Generic;
using System.Linq;
using Blazorise.Providers;
#endregion

namespace Blazorise.Icons.Material
{
    class MaterialIconProvider : BaseIconProvider
    {
        #region Members

        private static Dictionary<IconName, string> names = new()
        {
            { IconName.Add, "add" },
            { IconName.Adjust, "adjust" },
            { IconName.AlignCenter, "format_align_center" },
            { IconName.AlignJustify, "format_align_justify" },
            { IconName.AlignLeft, "format_align_left" },
            { IconName.AlignRight, "format_align_right" },
            { IconName.AngleDown, "arrow_drop_down" },
            { IconName.AngleLeft, "keyboard_arrow_left" },
            { IconName.AngleRight, "keyboard_arrow_right" },
            { IconName.AngleUp, "arrow_drop_up" },
            { IconName.Archive, "archive" },
            { IconName.ArrowAltCircleDown, "arrow_drop_down_circle" },
            { IconName.ArrowDown, "arrow_downward" },
            { IconName.ArrowLeft, "arrow_back" },
            { IconName.ArrowRight, "forward" },
            { IconName.ArrowUp, "arrow_upward" },
            { IconName.Baby, "child_care" },
            { IconName.BabyCarriage, "child_friendly" },
            { IconName.Backspace, "backspace" },
            { IconName.Backward, "fast_rewind" },
            { IconName.BalanceScale, "account_balance" },
            { IconName.Ban, "block" },
            { IconName.BandAid, "healing" },
            { IconName.Bars, "menu" },
            { IconName.BatteryFull, "battery_full" },
            { IconName.Bell, "notifications" },
            { IconName.BellSlash, "notifications_off" },
            { IconName.Biking, "directions_bike" },
            { IconName.BirthdayCake, "cake" },
            { IconName.Bold, "format_bold" },
            { IconName.Bolt, "flash_on" },
            { IconName.Book, "book" },
            { IconName.Bookmark, "bookmark" },
            { IconName.BookReader, "class" },
            { IconName.BorderAll, "border_all" },
            { IconName.BorderNone, "border_clear" },
            { IconName.BorderStyle, "border_style" },
            { IconName.Briefcase, "work" },
            { IconName.Brush, "brush" },
            { IconName.Bug, "bug_report" },
            { IconName.Building, "business" },
            { IconName.Bus, "directions_bus" },
            { IconName.CalendarCheck, "event_available" },
            { IconName.CalendarDay, "view_day" },
            { IconName.CalendarTimes, "event_busy" },
            { IconName.CalendarWeek, "view_week" },
            { IconName.Camera, "camera" },
            { IconName.CameraRetro, "camera_alt" },
            { IconName.Car, "directions_car" },
            { IconName.CaretSquareRight, "slideshow" },
            { IconName.CartPlus, "add_shopping_cart" },
            { IconName.Chair, "event_seat" },
            { IconName.ChartPie, "pie_chart" },
            { IconName.Check, "check" },
            { IconName.CheckCircle, "check_circle" },
            { IconName.CheckDouble, "done_all" },
            { IconName.CheckSquare, "check_box" },
            { IconName.ChevronLeft, "chevron_left" },
            { IconName.ChevronRight, "chevron_right" },
            { IconName.Circle, "radio_button_unchecked" },
            { IconName.City, "location_city" },
            { IconName.Clear, "clear" },
            { IconName.ClinicMedical, "local_pharmacy" },
            { IconName.Clock, "schedule" },
            { IconName.ClosedCaptioning, "closed_caption" },
            { IconName.Cloud, "cloud" },
            { IconName.CloudDownloadAlt, "cloud_download" },
            { IconName.CloudUploadAlt, "backup" },
            { IconName.Cocktail, "local_bar" },
            { IconName.Code, "code" },
            { IconName.Coffee, "local_cafe" },
            { IconName.Comment, "comment" },
            { IconName.CommentAlt, "comment" },
            { IconName.Comments, "chat" },
            { IconName.CompactDisc, "album" },
            { IconName.Compass, "explore" },
            { IconName.Compress, "fullscreen_exit" },
            { IconName.Copyright, "copyright" },
            { IconName.CreditCard, "credit_card" },
            { IconName.Crop, "crop" },
            { IconName.Dashboard, "dashboard" },
            { IconName.Delete, "delete" },
            { IconName.Desktop, "computer" },
            { IconName.Dice, "casino" },
            { IconName.Directions, "directions" },
            { IconName.Dog, "pets" },
            { IconName.DollarSign, "attach_money" },
            { IconName.DotCircle, "radio_button_checked" },
            { IconName.Download, "get_app" },
            { IconName.Dumbbell, "fitness_center" },
            { IconName.Edit, "edit" },
            { IconName.Eject, "eject" },
            { IconName.Ethernet, "settings_ethernet" },
            { IconName.EuroSign, "euro_symbol" },
            { IconName.Exclamation, "priority_high" },
            { IconName.ExclamationCircle, "error" },
            { IconName.ExclamationTriangle, "report_problem" },
            { IconName.Expand, "fullscreen" },
            { IconName.ExpandArrowsAlt, "zoom_out_map" },
            { IconName.ExpandLess, "expand_less" },
            { IconName.ExpandMore, "expand_more" },
            { IconName.ExternalLinkSquareAlt, "publish" },
            { IconName.Eye, "visibility" },
            { IconName.EyeSlash, "visibility_off" },
            { IconName.FastForward, "fast_forward" },
            { IconName.FileAlt, "description" },
            { IconName.FileDownload, "file_download" },
            { IconName.FilePdf, "picture_as_pdf" },
            { IconName.FileUpload, "file_upload" },
            { IconName.Film, "theaters" },
            { IconName.Filter, "filter" },
            { IconName.Fingerprint, "fingerprint" },
            { IconName.Fire, "whatshot" },
            { IconName.Flag, "flag" },
            { IconName.Flask, "science" },
            { IconName.Folder, "folder" },
            { IconName.FolderOpen, "folder_open" },
            { IconName.FolderPlus, "create_new_folder" },
            { IconName.Forward, "forward" },
            { IconName.Frown, "mood_bad" },
            { IconName.FrownOpen, "sentiment_dissatisfied" },
            { IconName.Gamepad, "gamepad" },
            { IconName.GasPump, "local_gas_station" },
            { IconName.Gavel, "gavel" },
            { IconName.Gift, "card_giftcard" },
            { IconName.Grin, "face" },
            { IconName.GripLines, "drag_handle" },
            { IconName.HandPaper, "pan_tool" },
            { IconName.HandsHelping, "live_help" },
            { IconName.Headphones, "headset" },
            { IconName.Headset, "headset" },
            { IconName.Heart, "favorite" },
            { IconName.Highlighter, "highlight" },
            { IconName.History, "history" },
            { IconName.Home, "home" },
            { IconName.Hospital, "local_hospital" },
            { IconName.Hotel, "hotel" },
            { IconName.HotTub, "hot_tub" },
            { IconName.Hourglass, "hourglass_empty" },
            { IconName.IdCard, "card_membership" },
            { IconName.Image, "image" },
            { IconName.Images, "photo_album" },
            { IconName.Inbox, "inbox" },
            { IconName.Indent, "format_indent_increase" },
            { IconName.Infinity, "all_inclusive" },
            { IconName.Info, "info" },
            { IconName.InfoCircle, "info" },
            { IconName.Italic, "format_italic" },
            { IconName.Key, "vpn_key" },
            { IconName.Keyboard, "keyboard" },
            { IconName.Language, "language" },
            { IconName.Laptop, "laptop" },
            { IconName.LaptopCode, "developer_mode" },
            { IconName.Laugh, "insert_emoticon" },
            { IconName.LayerGroup, "layers" },
            { IconName.Lightbulb, "wb_incandescent" },
            { IconName.Link, "link" },
            { IconName.List, "list" },
            { IconName.ListOl, "format_list_numbered" },
            { IconName.ListUl, "format_list_bulleted" },
            { IconName.LocationArrow, "navigation" },
            { IconName.Lock, "lock" },
            { IconName.LockOpen, "lock_open" },
            { IconName.Mail, "mail" },
            { IconName.Map, "map" },
            { IconName.MapMarker, "my_location" },
            { IconName.MapMarkerAlt, "room" },
            { IconName.Memory, "memory" },
            { IconName.Microphone, "mic" },
            { IconName.MicrophoneSlash, "mic_off" },
            { IconName.MinusCircle, "remove_circle" },
            { IconName.MinusSquare, "indeterminate_check_box" },
            { IconName.MoneyBillAlt, "local_atm" },
            { IconName.MoreHorizontal, "more_horiz" },
            { IconName.MoreVertical, "more_vert" },
            { IconName.Motorcycle, "motorcycle" },
            { IconName.Mouse, "mouse" },
            { IconName.Music, "music_note" },
            { IconName.PaintBrush, "brush" },
            { IconName.PaintRoller, "format_paint" },
            { IconName.Palette, "palette" },
            { IconName.Paperclip, "attach_file" },
            { IconName.PaperPlane, "send" },
            { IconName.Parking, "local_parking" },
            { IconName.Pause, "pause" },
            { IconName.PauseCircle, "pause_circle_filled" },
            { IconName.Pen, "edit" },
            { IconName.Phone, "phone" },
            { IconName.PhoneAlt, "phone" },
            { IconName.PizzaSlice, "local_pizza" },
            { IconName.Plane, "local_airport" },
            { IconName.PlaneArrival, "flight_land" },
            { IconName.PlaneDeparture, "flight_takeoff" },
            { IconName.Play, "play_arrow" },
            { IconName.PlayCircle, "play_circle_filled" },
            { IconName.Plug, "power" },
            { IconName.PlusCircle, "add_circle" },
            { IconName.PlusSquare, "add_box" },
            { IconName.Poll, "poll" },
            { IconName.Portrait, "portrait" },
            { IconName.Print, "print" },
            { IconName.PuzzlePiece, "extension" },
            { IconName.QuestionCircle, "help" },
            { IconName.QuoteRight, "format_quote" },
            { IconName.Random, "shuffle" },
            { IconName.Receipt, "receipt" },
            { IconName.Redo, "redo" },
            { IconName.Remove, "remove" },
            { IconName.RemoveFormat, "format_clear" },
            { IconName.Reply, "reply" },
            { IconName.ReplyAll, "reply_all" },
            { IconName.Restroom, "wc" },
            { IconName.Rss, "rss_feed" },
            { IconName.RulerHorizontal, "straighten" },
            { IconName.Running, "directions_run" },
            { IconName.Satellite, "satellite" },
            { IconName.Save, "save" },
            { IconName.School, "school" },
            { IconName.SdCard, "sd_card" },
            { IconName.Search, "search" },
            { IconName.SearchMinus, "zoom_out" },
            { IconName.SearchPlus, "zoom_in" },
            { IconName.Seedling, "local_florist" },
            { IconName.Server, "dns" },
            { IconName.Shapes, "format_shapes" },
            { IconName.Share, "share" },
            { IconName.ShareAlt, "share" },
            { IconName.ShieldAlt, "security" },
            { IconName.Ship, "directions_boat" },
            { IconName.ShoppingBag, "shop" },
            { IconName.ShoppingBasket, "shopping_basket" },
            { IconName.ShoppingCart, "shopping_cart" },
            { IconName.ShuttleVan, "airport_shuttle" },
            { IconName.SimCard, "sim_card" },
            { IconName.SliderHorizontal, "tune" },
            { IconName.Smartphone, "smartphone" },
            { IconName.Smile, "mood" },
            { IconName.Smoking, "smoking_rooms" },
            { IconName.SmokingBan, "smoke_free" },
            { IconName.Sms, "sms" },
            { IconName.Snowflake, "ac_unit" },
            { IconName.Sort, "sort" },
            { IconName.SortAlphaDown, "sort_by_alpha" },
            { IconName.SortAmountDownAlt, "sort" },
            { IconName.SortDown, "arrow_drop_down" },
            { IconName.SortUp, "arrow_drop_up" },
            { IconName.Spa, "spa" },
            { IconName.SpellCheck, "spellcheck" },
            { IconName.Square, "check_box_outline_blank" },
            { IconName.Star, "star" },
            { IconName.StarHalf, "star_half" },
            { IconName.StepBackward, "skip_previous" },
            { IconName.StepForward, "skip_next" },
            { IconName.StickyNote, "note_add" },
            { IconName.Stop, "stop" },
            { IconName.Store, "store" },
            { IconName.StoreAlt, "store_mall_directory" },
            { IconName.Stream, "view_stream" },
            { IconName.StreetView, "streetview" },
            { IconName.Strikethrough, "format_strikethrough" },
            { IconName.Subscript, "subscript" },
            { IconName.Subway, "subway" },
            { IconName.Suitcase, "business_center" },
            { IconName.Sun, "wb_sunny" },
            { IconName.Superscript, "superscript" },
            { IconName.SwimmingPool, "pool" },
            { IconName.Sync, "sync" },
            { IconName.SyncAlt, "cached" },
            { IconName.Tablet, "tablet" },
            { IconName.Tag, "local_offer" },
            { IconName.Taxi, "local_taxi" },
            { IconName.TextHeight, "format_size" },
            { IconName.ThumbsDown, "thumb_down" },
            { IconName.ThumbsUp, "thumb_up" },
            { IconName.TicketAlt, "local_activity" },
            { IconName.Times, "close" },
            { IconName.TimesCircle, "highlight_off" },
            { IconName.Tint, "invert_colors" },
            { IconName.TintSlash, "invert_colors_off" },
            { IconName.TrafficLight, "traffic" },
            { IconName.Train, "train" },
            { IconName.Tram, "tram" },
            { IconName.Tree, "nature" },
            { IconName.Truck, "local_shipping" },
            { IconName.Tv, "tv" },
            { IconName.UmbrellaBeach, "beach_access" },
            { IconName.Underline, "format_underlined" },
            { IconName.Undo, "undo" },
            { IconName.Unlock, "no_encryption" },
            { IconName.User, "person" },
            { IconName.UserCheck, "verified_user" },
            { IconName.UserCircle, "account_circle" },
            { IconName.UserFriends, "group" },
            { IconName.UserPlus, "group_add" },
            { IconName.Users, "group_work" },
            { IconName.UserTie, "supervisor_account" },
            { IconName.Utensils, "restaurant" },
            { IconName.Video, "videocam" },
            { IconName.VideoSlash, "videocam_off" },
            { IconName.Voicemail, "voicemail" },
            { IconName.VolumeDown, "volume_down" },
            { IconName.VolumeMute, "volume_mute" },
            { IconName.VolumeOff, "volume_off" },
            { IconName.VolumeUp, "volume_up" },
            { IconName.Walking, "directions_walk" },
            { IconName.Wallet, "account_balance_wallet" },
            { IconName.Wheelchair, "accessible" },
            { IconName.Wifi, "wifi" },
            { IconName.WineBottle, "local_drink" },
            { IconName.Wrench, "build" },
        };

        private static Dictionary<IconStyle, string> styles = new()
        {
            { IconStyle.Solid, "material-icons" },
            { IconStyle.Regular, "material-icons-outlined" },
            { IconStyle.Light, "material-icons-sharp" }, // TODO: probably not correct
            { IconStyle.DuoTone, "material-icons-two-tone" },
        };

        // Some material icons have a special outline names so we need to override them.
        private static Dictionary<string, string> outlineNameOverrides = new()
        {
            { "star", "star_outline" }
        };

        #endregion

        #region Methods

        public override string IconSize( IconSize iconSize )
        {
            return iconSize switch
            {
                Blazorise.IconSize.ExtraSmall => "md-xs",
                Blazorise.IconSize.Small => "md-sm",
                Blazorise.IconSize.Large => "md-lg",
                Blazorise.IconSize.x2 => "md-2x",
                Blazorise.IconSize.x3 => "md-3x",
                Blazorise.IconSize.x4 => "md-4x",
                Blazorise.IconSize.x5 => "md-5x",
                Blazorise.IconSize.x6 => "md-6x",
                Blazorise.IconSize.x7 => "md-7x",
                Blazorise.IconSize.x8 => "md-8x",
                Blazorise.IconSize.x9 => "md-9x",
                Blazorise.IconSize.x10 => "md-10x",
                _ => null,
            };
        }

        public override string GetIconName( IconName iconName, IconStyle iconStyle )
        {
            if ( names.TryGetValue( iconName, out var value ) )
            {
                if ( iconStyle == IconStyle.Regular && outlineNameOverrides.TryGetValue( value, out var valueOverride ) )
                    return valueOverride;

                return value;
            }

            return null;
        }

        public override void SetIconName( IconName name, string newName )
        {
            names[name] = newName;
        }

        public override string GetStyleName( IconStyle iconStyle )
        {
            if ( styles.TryGetValue( iconStyle, out var style ) )
                return style;

            return null;
        }

        protected override bool ContainsStyleName( string iconName )
        {
            return iconName.Split( ' ' ).Any( x => styles.Values.Contains( x ) || new string[] { "material-icons-round" }.Contains( x ) );
        }

        #endregion

        #region Properties

        public override bool IconNameAsContent => true;

        #endregion
    }
}
